<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>显示所有员工信息</title>
    <link rel="stylesheet" href="webjars/bootstrap/3.3.5/css/bootstrap.css" type="text/css">
    <script src="webjars/jquery/3.4.1/jquery.js"></script>
</head>
<body>
<h2>员工信息列表&emsp;&emsp;<button type="button" onclick="history.go(-1)" class="glyphicon glyphicon-share-alt" aria-hidden="true" th:bgcolor="grey"></button></h2>
<table>
    <form action="/searchE">
        <tr>
            <td>查询条件：&emsp;</td>
            <td><input name="name" type="text" placeholder="请输入员工姓名"></td>
            <!-- <td>类型</td><td><input name="type" type="text"></td>-->
            <td>&emsp;<input type="submit" value="查询"></td>
            <td>&emsp;&emsp;&emsp;&emsp;&emsp;<a th:href="@{'/addEmp'}" class="btn btn-info">
                <!-- <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>-->
                    <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>增加</a>
            </td>
        </tr>
    </form>
</table><br>
<table class="table table-hover">
    <tr>
        <th>员工编号</th>
        <th>员工姓名</th>
        <th>性别</th>
        <th>年龄</th>
        <th>员工号</th>
        <th>员工类别</th>
        <th>入职时间</th>
        <th>操作人</th>
        <th>操作时间</th>
        <th>职务</th>
        <th>职称</th>
        <th>人员状态</th>
        <th>简介</th>
        <th>备注</th>
        <th>其它操作</th>
    </tr>
    <tr th:each="emp:${emps}">
        <td th:text="${emp.id}"></td>
        <td th:text="${emp.name}"></td>
        <td th:text="${emp.sex}"></td>
        <td th:text="${emp.age}"></td>
        <td th:text="${emp.emnumber}"></td>
        <td th:text="${emp.type}"></td>
        <td th:text="${emp.entrytime}"></td>
        <td th:text="${emp.operator}"></td>
        <td th:text="${emp.optime}"></td>
        <td th:text="${emp.position}"></td>
        <td th:text="${emp.jobtitle}"></td>
        <td th:text="${emp.status}"></td>
        <td th:text="${emp.introduction}"></td>
        <td th:text="${emp.remarks}"></td>
        <td>
            <a th:href="@{'/employee/'+${emp.id}}" class="btn btn-info">修改</a>
            <a th:onclick="|deleteEmp(this, ${emp.id})|" class="btn btn-warning">删除</a>
        </td>
    </tr>
</table>
<script>
    function deleteEmp(obj,id) {
        if(confirm("确定要删除么？")){
            alert("要删除的部门编号："+id);
            //发送删除操作请求
            $.ajax({
                url: "/employee/"+id,
                type: "DELETE",
                success: function (result) {
                    // alert(result);
                    if(result==="success"){
                        //删除当前行
                        $(obj ).parent().parent().remove();
                    }else{
                        alert("这个部门不能删除....");
                    }
                }
            });
        }else{
            alert("撤销删除操作")
        }

    }
</script>
</body>
</html>